package learningThread.syn.synchronizedMethodLockObj.lock.fairLock;

/**
 * 公平锁的执行顺序时有序的，说明先start启动的线程先获得锁
 * 非公平锁的执行顺序时乱序的，说明先start启动的线程不代表获得锁
 */
public class TestFairLock {

    public static void main(String[] args) {
        //公平锁
        //Service service = new Service(true);
        //非公平锁
        Service service = new Service(false);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println(" * 线程:"+Thread.currentThread().getName());
                service.serviceMethod();
            }
        };

        Thread[] threads = new Thread[10];
        for (int i = 0; i < 10; i++) {
            threads[i] = new Thread(runnable);
        }
        for (int i = 0; i < threads.length; i++) {
            threads[i].start();
        }

    }
}
